// 获取所有班级的中文名称和其部门编号的对象数组
var res_list = []
const recursive = (name, rel, obj) => {
	let _rel = rel.slice();
	if (obj.children.length == 0) {
		_rel.push(obj.id)
		res_list.push({
			id: obj.id,
			name: name + obj.name,
			rel: _rel
		})
		return
	}
	
	if (obj.children.length != 0) { 
		name += obj.name
		
		obj.children.forEach(ele => {
			_rel.push(obj.id)
			recursive(name, _rel, ele)
			_rel.pop()
		})
		
	}
} 

const get_dept_id_map = (obj) => {
	res_list = []
	recursive('', [],obj)
	console.log('get_dept_id_map', res_list)
	return res_list
}




let node = null
const dfs = (obj, name) => {
	// console.log(name, obj.name, node)
	if (obj.id === name) {
		console.log('dfs中找到')
		node = obj
		return
	}
	// 剪枝策略 
	if (node !== null) {
		return
	}
	if (obj.children && obj.children.length !== 0) { 
		obj.children.forEach(ele => {
			dfs(ele, name)
		})
	}
}

// 查找树中节点name为指定值的节点
// param: obj 根节点 name
const locate_node_by_name = (obj, name) => {
	// console.log('obj name', obj.name)
	node = null
	dfs(obj, name)
	return node
}

export default {
	get_dept_id_map: get_dept_id_map,
	locate_node_by_name: locate_node_by_name
	
}